﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.txtDir.Text == "")
            {
                MessageBox.Show("请选择下载文件夹");
                this.txtDir.Focus();
                return;
            }
            int[] tPSize = new int[] { 96, 72, 64, 48, 32, 24, 16 };
            string[] tPType = new string[] { "png", "ico" };
            int Star = Convert.ToInt32(this.maskedNum1.Text);
            int end = Convert.ToInt32(this.maskedNum2.Text);
           // string strBegin = this.txtStart.Text;
            for (int i = Star; i < end; i++)
            {
                for (int j = 0; j < tPSize.Length; j++)
                {
                    int tSize = tPSize[j];
                    string sysDir = this.txtDir.Text;
                    string sysPng = "png";
                    sysDir = sysDir + "\\" + sysPng + "\\" + tSize.ToString();
                    if (!System.IO.Directory.Exists(sysDir))
                    {
                        System.IO.Directory.CreateDirectory(sysDir);
                    }

                    string fileName = i + "." + sysPng;
                    string str = this.txtUrl.Text+"/"+sysPng+"/"+i + "/" + tSize + "/";
                    this.pictureBox1.Load(str);
                    if (this.pictureBox1.Image != null)
                    {
                        this.pictureBox1.Image.Save(sysDir + "\\" + fileName, System.Drawing.Imaging.ImageFormat.Png);
                    }

                }



            }
            MessageBox.Show("完成");
        }

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {

        }

        private void btDir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog tFBD = new FolderBrowserDialog();
            if (tFBD.ShowDialog() == DialogResult.OK)
            {
                this.txtDir.Text = tFBD.SelectedPath;
            }
        }
    }
}
